package com.example.nonacademic_education.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.nonacademic_education.data.response.DepartmentDto;
import com.example.nonacademic_education.data.response.FileItemGrantDto;
import com.example.nonacademic_education.entity.Department;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author:yanghua
 * @Date:2023/4/18 17:14
 */

public interface DepartmentDao extends BaseMapper<Department> {


    @Update("update department set is_del = 1 where id=#{id};")
    Boolean deleteOne(Long id);

    List<Department> getList(int page, int size, String name);

    Integer getNumber(String name);

    List<DepartmentDto> getIdAndNameList(String name);

    @Select("select name from department where id=#{departmentId}")
    String getNameById(Long departmentId);

    @Select("select * from department where id=#{departmentId}")
    Department getOneById(Long departmentId);

    @Update("update department set certificate_no=#{i} where id=#{id}")
    Integer updateCertificateNo(int i, Long id);

    @Select("select * from department where id=(select p.department_id from project p where p.id=(select tc.project_id from theclass tc where tc.id=#{classId} and tc.is_del=0 limit 1) and p.is_del=0 limit 1)")
    Department getOneByClassId(Long classId);

    @Select("select id,name as departmentName from department where id!=0 and is_del=0")
    List<FileItemGrantDto> getFileItemGrantList();

    @Select("select certificate_no from department where id=(select p.department_id from project p where p.id=(select tc.project_id from theclass tc where tc.id=#{classId}))")
    Integer getMaxNoByClassId(Long classId);

    @Update("update department set certificate_no=#{maxNoThisClass} where id=(select p.department_id from project p where p.id=(select tc.project_id from theclass tc where tc.id=#{classId}))")
    Integer updateNoByClassId(Integer maxNoThisClass, Long classId);

    @Update("update department set certificate_no=1")
    Integer updateCertificateNoQuartz();
}
